package com.edushare.common.dao
;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import com.edushare.common.orm.ORMInterface;
import com.edushare.common.vo.AttendanceRegister;
import com.edushare.common.vo.CourseInstances;

public class AttendanceRegisterDAO extends CayenneBasedDAO {

	public class SortRegisterByDate implements Comparator<AttendanceRegister> {

		public int compare(AttendanceRegister o1, AttendanceRegister o2) {
			return o1.getAttdDate().compareTo(o2.getAttdDate());
		}
		
	}

	public AttendanceRegisterDAO(ORMInterface ormInterface) {
		super(ormInterface);
	}
	
	public List<AttendanceRegister> getMonthlyAttendanceList(Date dateInMonth, CourseInstances ci){
		List<AttendanceRegister> arl = ci.getAttendanceRegister();
		Calendar reqDate = new GregorianCalendar();
		reqDate.setTime(dateInMonth);
		
		ArrayList<AttendanceRegister> sublist = new ArrayList<AttendanceRegister>();
		for(AttendanceRegister ar: arl){
			Calendar attdDate = new GregorianCalendar();
			attdDate.setTime(ar.getAttdDate());
			if(attdDate.get(Calendar.MONTH)==reqDate.get(Calendar.MONTH))
				sublist.add(ar);
		}
		Collections.sort(sublist, new SortRegisterByDate());
		return sublist;
	}

}
